/*
*  Copyright 2019-2023 CY
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.ejweixin.rest;

import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.ejweixin.domain.NgConstructionSiteInfoStaff;
import me.zhengjie.modules.ejweixin.service.NgConstructionSiteInfoStaffService;
import me.zhengjie.modules.ejweixin.domain.vo.NgConstructionSiteInfoStaffQueryCriteria;
import lombok.RequiredArgsConstructor;
import java.util.List;

import me.zhengjie.utils.Result;
import net.dreamlu.mica.core.result.R;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import me.zhengjie.utils.PageResult;

/**
* @author cy
* @date 2025-04-23
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "工地人员管理")
@RequestMapping("/api/ngConstructionSiteInfoStaff")
public class NgConstructionSiteInfoStaffController {

    private final NgConstructionSiteInfoStaffService ngConstructionSiteInfoStaffService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('ngConstructionSiteInfoStaff:list')")
    public void exportNgConstructionSiteInfoStaff(HttpServletResponse response, NgConstructionSiteInfoStaffQueryCriteria criteria) throws IOException {
        ngConstructionSiteInfoStaffService.download(ngConstructionSiteInfoStaffService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询工地人员")
    @ApiOperation("查询工地人员")
    @PreAuthorize("@el.check('ngConstructionSiteInfoStaff:list')")
    public ResponseEntity<PageResult<NgConstructionSiteInfoStaff>> queryNgConstructionSiteInfoStaff(NgConstructionSiteInfoStaffQueryCriteria criteria, Page<Object> page){
        return new ResponseEntity<>(ngConstructionSiteInfoStaffService.queryAll(criteria,page),HttpStatus.OK);
    }

    @GetMapping("staffList")
    @Log("查询工地人员")
    @ApiOperation("查询工地人员")
    @AnonymousAccess
    public ResponseEntity<Object> staffList(int siteId){
        return new ResponseEntity<>(ngConstructionSiteInfoStaffService.staffList(siteId),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增工地人员")
    @ApiOperation("新增工地人员")
    @PreAuthorize("@el.check('ngConstructionSiteInfoStaff:add')")
    public ResponseEntity<Object> createNgConstructionSiteInfoStaff(@Validated @RequestBody NgConstructionSiteInfoStaff resources){
        ngConstructionSiteInfoStaffService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改工地人员")
    @ApiOperation("修改工地人员")
    @PreAuthorize("@el.check('ngConstructionSiteInfoStaff:edit')")
    public ResponseEntity<Object> updateNgConstructionSiteInfoStaff(@Validated @RequestBody NgConstructionSiteInfoStaff resources){
        ngConstructionSiteInfoStaffService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除工地人员")
    @ApiOperation("删除工地人员")
    @PreAuthorize("@el.check('ngConstructionSiteInfoStaff:del')")
    public ResponseEntity<Object> deleteNgConstructionSiteInfoStaff(@RequestBody List<Integer> ids) {
        ngConstructionSiteInfoStaffService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @GetMapping("getUnassigned")
    @Log("查询工地人员")
    @ApiOperation("查询工地人员")
    @AnonymousAccess
    public Result<List<Map<String, Object>>> getUnassigned(Integer id){
        return Result.success(ngConstructionSiteInfoStaffService.getStaffW(id));
    }

    @GetMapping("getAssigned")
    @Log("查询工地人员")
    @ApiOperation("查询工地人员")
    @AnonymousAccess
    public Result<List<Map<String, Object>>> getAssigned(Integer id){
        return Result.success(ngConstructionSiteInfoStaffService.getStaffY(id));
    }
    @PostMapping("saveStaff")
    @Log("新增工地人员")
    @ApiOperation("新增工地人员")
    public Result<Object> assign( @RequestBody Object data){
        ngConstructionSiteInfoStaffService.saveStaff(data);
        return Result.success("ok");
    }
}